package com.talkweb.calendarview;

import ohos.agp.components.AttrSet;

public class AttrSetUtils {

    public static int getColor(AttrSet attrSet, String styleStr, int defaultValue) {
        try{
            int value = attrSet.getAttr(styleStr).get().getColorValue().getValue();
            return value;
        }catch (Exception ex){
            return defaultValue;
        }
    }

    public static int getDimension(AttrSet attrSet, String styleStr, int defaultValue) {
        try{
            int value = attrSet.getAttr(styleStr).get().getDimensionValue();
            return value;
        }catch (Exception ex){
            return defaultValue;
        }
    }

    public static String getString(AttrSet attrSet, String styleStr, String defaultValue) {
        try{
            String value = attrSet.getAttr(styleStr).get().getStringValue();
            return value;
        }catch (Exception ex){
            return defaultValue;
        }
    }

    public static int getInt(AttrSet attrSet, String styleStr, int defaultValue) {
        try{
            int value = attrSet.getAttr(styleStr).get().getIntegerValue();
            return value == -1 ? defaultValue : value;
        }catch (Exception ex){
            return defaultValue;
        }
    }

    public static boolean getBoolean(AttrSet attrSet, String styleStr, boolean defaultValue) {
        try{
            boolean value = attrSet.getAttr(styleStr).get().getBoolValue();
            return value;
        }catch (Exception ex){
            return defaultValue;
        }
    }

}
